<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        .register-box {
            border: 1px solid #ccc;
            padding: 20px;
            width: 300px;
            margin: 50px auto;
        }
        input[type="text"], input[type="password"], input[type="email"] {
            width: 100%;
            padding: 8px;
            margin: 8px 0;
        }
        .btn {
            display: inline-block;
            padding: 8px 16px;
            margin: 8px 4px 0 0;
            height: 36px;
            line-height: 20px;
            cursor: pointer;
            border: 1px solid #888;
            background: #f5f5f5;
        }
        .flash-success { color: #155724; background:#d4edda; padding:8px; border-radius:4px; margin-bottom:10px; }
        .flash-error { color: #721c24; background:#f8d7da; padding:8px; border-radius:4px; margin-bottom:10px; }
        .flash-warning { color: #856404; background:#fff3cd; padding:8px; border-radius:4px; margin-bottom:10px; }
        .field-error { color: #b94a48; font-size: 0.9em; margin-top:4px; }
        .login-link { text-align: center; margin-top: 20px; }
    </style>
</head>
<body>
    <div class="register-box">
        <h2>注册</h2>

        {% with messages = get_flashed_messages(with_categories=true) %}
          {% if messages %}
            {% for category, msg in messages %}
              {% if category == 'success' %}
                <div class="flash-success">{{ msg }}</div>
              {% elif category == 'error' %}
                <div class="flash-error">{{ msg }}</div>
              {% else %}
                <div class="flash-warning">{{ msg }}</div>
              {% endif %}
            {% endfor %}
          {% endif %}
        {% endwith %}

        <form method="post" novalidate>
            {{ form.hidden_tag() }}

            <label for="username">用户名</label>
            {{ form.username(id='username') }}
            {% if form.username.errors %}
                <div class="field-error">{{ form.username.errors[0] }}</div>
            {% endif %}

            <label for="password">密码</label>
            {{ form.password(id='password') }}
            {% if form.password.errors %}
                <div class="field-error">{{ form.password.errors[0] }}</div>
            {% endif %}

            <label for="confirm_password">再次输入密码</label>
            {{ form.confirm_password(id='confirm_password') }}
            {% if form.confirm_password.errors %}
                <div class="field-error">{{ form.confirm_password.errors[0] }}</div>
            {% endif %}

            <label for="email">邮箱</label>
            {{ form.email(id='email') }}
            {% if form.email.errors %}
                <div class="field-error">{{ form.email.errors[0] }}</div>
            {% endif %}

            {{ form.submit(class="btn") }}
            <button type="reset" class="btn">取消</button>
        </form>

        <div class="login-link">
            <p>已有账号？<a href="/login">点我登录</a></p>
        </div>
    </div>
    
    <!-- 会话超时管理 -->
    <script src="/static/js/session-timeout.js"></script>
</body>
</html>